package com.fiume.travel.config;

/**
 * <p>
 * Description:声明启动时加载的类
 * </p>
 *
 * @author fiume
 * @version v1.0.0
 * @create 2021-02-22 22:45
 * @see com.fiume.travel.config
 */

import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

@Configuration
public class ProjectConfig extends AbstractAnnotationConfigDispatcherServletInitializer {

    /**
     * 配置字符过滤
     * @param servletContext 容器
     * @return
     */
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
        //字符集
        FilterRegistration.Dynamic dynamic = servletContext.addFilter("encodingFilter", CharacterEncodingFilter.class);
        dynamic.setInitParameter("encoding", "UTF-8");
        dynamic.addMappingForUrlPatterns(null, true, "/*");
    }

    /**
     * 配置服务器启动加载Spring的配置类和Mybatis的配置类
     * @return
     */
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class, MybatisConfig.class};
    }

    /**
     * 服务器启动时加载SpringMVC的配置类
     * @return
     */
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{PlatformSpringMvcConfig.class};
    }

    /**
     * 配置DispatcherServlet过滤的路径
     * @return
     */
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}
